﻿using System;
using System.Runtime.CompilerServices;

namespace HW0324_2
{
    class Program
    {
        static void Main()
        {
            Random ran = new Random();
            List<int> ints = new List<int>();
            for (int i = 0; i<100; i++)
                ints.Add(ran.Next(0, 1000));
            Console.WriteLine("Initialize the list as: ");
            for (int i = 0; i<100; ) //  No i++ here!
            {
                for (int j = 0; j < 10; j++)
                {
                    Console.Write("{0,-3}",ints[i]);
                    Console.Write(" ");
                    i++;
                }
                Console.WriteLine();
            }
            var tmp = from i in ints
                      orderby i
                      select i;
            ints = tmp.ToList();
            Console.WriteLine("\nSort the list: ");
            for (int i = 0; i < 100;) //  No i++ here!
            {
                for (int j = 0; j < 10; j++)
                {
                    Console.Write("{0,-3}", ints[i]);
                    Console.Write(" ");
                    i++;
                }
                Console.WriteLine();
            }
            var sum = from i in ints
                      select ints.Sum(i => i);
            Console.WriteLine("\nThe sum of it is: " + sum.FirstOrDefault());
            var average = from i in ints
                          select ints.Average(i => i);
            Console.WriteLine("\nThe average of it is: "+average.FirstOrDefault());            
        }
    }
}